var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { useMemo } from 'react';
import { Image as ImageComponent } from '@tarojs/components';
import './index.scss';
var webp = 'image/auto-orient,1/quality,q_100/format,webp';
/**
 * Image 图片组件
 */
var Image = function (_a) {
    var _b = _a.autoCalcSize, autoCalcSize = _b === void 0 ? true : _b, _c = _a.scale, scale = _c === void 0 ? 1 : _c, props = __rest(_a, ["autoCalcSize", "scale"]);
    var uriSource = props.src;
    var finalSource = useMemo(function () {
        var flattenStyle = props.style;
        var imageWidth = (flattenStyle && flattenStyle.width) || 300;
        imageWidth = Math.floor(imageWidth);
        if (isNaN(imageWidth)) {
            imageWidth = 600;
        }
        var uri = uriSource;
        if (uri &&
            uri.startsWith('http') &&
            (uri.indexOf('yryz.com') != -1 ||
                uri.indexOf('yryz2.com') != -1 ||
                uri.indexOf('lajsf.com') != -1)) {
            if (uri.indexOf('visitcard/images/') != -1)
                return uri;
            if (uri.indexOf('gif') != -1)
                return uri;
            if (autoCalcSize) {
                var param = "x-oss-process=image/resize,m_lfit,h_0,w_" + imageWidth *
                    scale;
                uri += "" + (uri.includes('?') ? '&' : '?') + param;
            }
            if (uri.includes('x-oss-process')) {
                uri += ',' + webp;
            }
            else {
                uri += (uri.includes('?') ? '&' : '?') + 'x-oss-process=' + webp;
            }
            var finalSource_1 = uri;
            return finalSource_1;
        }
        return uriSource;
    }, [uriSource, autoCalcSize, props.style]);
    return React.createElement(ImageComponent, __assign({ lazyLoad: true }, props, { webp: true, src: finalSource }));
};
export default Image;
